#include "geometry.h"
#include "font.h"

void lcd_test(void)
{
    unsigned int fb_base;
    int xres , yres, bpp;
    int x,y;
    unsigned short *p;
    unsigned int *p2;

    //init lcd 
    lcd_init();

    lcd_enalbe();

    get_lcd_params(&fb_base, &xres,&yres,&bpp);

    fb_get_lcd_params();

    font_init();
    //write data to framebuffer
    if(bpp == 16)
    {
	//all red
	// 565 : 0xf800
	p = (unsigned short *)fb_base;
	for (x = 0; x < xres; ++x) {
	    for (y = 0; y < yres; ++y) {
		*p++ = 0xf800;    
	    }

	}

	//all green
	p = (unsigned short *)fb_base;
	for (x = 0; x < xres; ++x) {
	    for (y = 0; y < yres; ++y) {
		*p++ = 0x7e0;    
	    }

	}

	//all blue 
	p = (unsigned short *)fb_base;
	for (x = 0; x < xres; ++x) {
	    for (y = 0; y < yres; ++y) {
		*p++ = 0x1f;    
	    }

	}

    }else if (bpp == 32) {

	p2 = (unsigned short *)fb_base;
	for (x = 0; x < xres; ++x) {
	    for (y = 0; y < yres; ++y) {
		*p2++ = 0xff0000;    
	    }

	}

	//all green
	p2 = (unsigned short *)fb_base;
	for (x = 0; x < xres; ++x) {
	    for (y = 0; y < yres; ++y) {
		*p2++ = 0x00ff00;    
	    }

	}

	//all blue 
	p2 = (unsigned short *)fb_base;
	for (x = 0; x < xres; ++x) {
	    for (y = 0; y < yres; ++y) {
		*p2++ = 0x0000ff;    
	    }

	}

	p2 = (unsigned int *)fb_base;
	for (x = 0; x < xres; ++x) {
	    for (y = 0; y < yres; y++) {
	       *p2++ = 0; 
	    }
	}

    }

    delay(10000);

    /* 画线 */
    draw_line(0, 0, xres - 1, 0, 0xff0000);
    draw_line(xres - 1, 0, xres - 1, yres - 1, 0xffff00);
    draw_line(0, yres - 1, xres - 1, yres - 1, 0xff00aa);
    draw_line(0, 0, 0, yres - 1, 0xff00ef);
    draw_line(0, 0, xres - 1, yres - 1, 0xff4500);
    draw_line(xres - 1, 0, 0, yres - 1, 0xff0780);

    delay(10000);

    /* 画圆 */
    draw_circle(xres/2, yres/2, yres/4, 0xff00);

    // 文字
    fb_print_string(10,10,"i am rain !\r\n who are you?",0xff00);
}
